import React from "react"

import http from "@/api/helper/request"

import {
	IAuditRecordParams,
	ILockRecordParams,
	IQueryItemDetailParams,
	IQueryListParams,
	IResponseItem,
	IResponseItemDetail
} from "./types"

export const LIST_URL = {
	URL1: "/memberWithDrawUser/selectMemberWithDrawAudit1Page",
	URL2: "/memberWithDrawUser/selectMemberWithDrawAudit2Page"
}

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined, config: object = {}) {
		setLoading(true)
		let ret = await http.post<T>(url, body, config)
		setLoading(false)
		return ret
	}

	const getList = (url: string, body?: IQueryListParams) => generalHttp<Business.TableResourceType<IResponseItem>>(url, body)

	const getDetail = (body?: IQueryItemDetailParams) =>
		generalHttp<IResponseItemDetail>("/memberWithDrawUser/memberWithdrawAuditDetail", body)

	const lockRecord = (body?: ILockRecordParams) => generalHttp("/memberWithDrawUser/updateWithdrawLock", body)

	const auditRecord = (body?: IAuditRecordParams) => generalHttp("/memberWithDrawUser/updateWithdraw", body)

	return {
		loading,
		generalHttp,
		getList,
		getDetail,
		lockRecord,
		auditRecord
	}
}

export default useApi
